<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>发布 - 我的社区</title>
    <script src="js/jquery-3.3.1.min.js"></script>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="css/community.css">
    <script src="js/bootstrap.min.js"></script>
</head>
<body>

<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">我的社区</span>
            </button>
            <a class="navbar-brand" href="#">我的社区</a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <form class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="搜索话题">
                </div>
                <button type="submit" class="btn btn-default">搜索</button>
            </form>
            <ul class="nav navbar-nav navbar-right">
                <li><a th:if="${session.user == null}"
                       href="https://github.com/login/oauth/authorize?client_id=b675661f86d5de20d997&redirect_uri=http://localhost:8888/callback&scope=user&state=1">登录</a>
                </li>
                <li class="dropdown" th:unless="${session.user == null}">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false"><span th:text="${session.user.getName()}"></span><span
                            class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">消息中心</a></li>
                        <li><a href="#">个人资料</a></li>
                        <li><a href="#">退出登录</a></li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
</nav>
<div class="container-fluid main">
    <div class="row">
        <div class="col-lg-9 col-md-12 col-sm-12">
            <h2><span class="glyphicon glyphicon-plus" aria-hidden="true"></span>发起</h2>
            <hr>
            <form>
                <div class="form-group">
                    <label for="title">问题标题 (简单扼要) :</label>
                    <input type="text" class="form-control" id="title" name="title" placeholder="问题标题...">
                </div>
                <div class="form-group">
                    <label for="title">问题补充 (必填，请参照右边提示) :</label>
                    <textarea class="form-control" name="description" id="description" cols="30" rows="10"></textarea>
                </div>
                <div class="form-group">
                    <label for="title">添加标签 :</label>
                    <input type="text" class="form-control" id="tag" name="tag" placeholder="输入标签，以逗号分隔">
                </div>
                <button type="button" onclick="commit()" class="btn btn-success btn-publish">确认发起</button>
            </form>
        </div>
        <div class="col-lg-3 col-md-12 col-sm-12">
            <h3>问题发起指南</h3>
            <ul>
                <li>问题标题:请用精简的语言描述您发布的问题，不超过25字</li>
                <li>问题补充:详细补充您的问题内容，并确保问题描述清晰直观，并提供一些相关的资料</li>
                <li>选择标签:选择一个或者 多个合适的标签，用逗号隔开，不超过10个字</li>
                <li>关于积分:发起一个问题会消耗您20个积分，每多个回复你将获得5个积分的奖励 ,为了您的利益，在发起问题的时候希望能够更好的描述您的问题以及多使用站内搜索功能.</li>
            </ul>
        </div>
    </div>
</div>
<script type="text/javascript">
    function commit() {
        let title = $("#title").val();
        let description = $("#description").val();
        let tag = $("#tag").val();
        $.ajax({
            type: "post",
            url: "/publish",
            data: JSON.stringify({
                "title": title,
                "description": description,
                "tag": tag
            }),
            contentType: "application/json;charset=UTF-8",
            dataType: "json",
            success: function (data) {
                console.log(data);
            },
            error: function (e) {
                console.log(e);
            }
        })
    }
</script>
</body>
</html>
